<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Conf\ConfModel;

use Srv\Libs\Frame\Conf;

final class StorageConfGroup
{
    private array $StorageConfGroupNameList                 = [];       // StorageConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $StorageConfList              = [];
        $groupNameList              = Conf::getGroupNameList(StorageConf::PREFIX);
        if(count($groupNameList) < 1) return $StorageConfList;
        foreach ($groupNameList as $groupName){
            $StorageConf              = $this->getByGroupName($groupName);
            if($StorageConf instanceof StorageConf) $StorageConfList[$groupName] = $StorageConf;
        }
        return $StorageConfList;
    }

    /**
     * @param string $groupName
     * @return StorageConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?StorageConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->StorageConfGroupNameList[$groupName]) && $this->StorageConfGroupNameList[$groupName] instanceof StorageConf) return $this->StorageConfGroupNameList[$groupName];
        $confData                                   = Conf::getGroupList(StorageConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->StorageConfGroupNameList[$groupName] = new StorageConf($confData, $groupName);
        return $this->StorageConfGroupNameList[$groupName];
    }
}